DSA Homework 3

Roger Jang


Due date: 20160417 23:59:59
This homework include a hand-written part and a programming part.

Hand-written Part (20%)

For the hand-written part, you can use any theorems in the textbook and any theorems on the class slides as the foundation of your proof. You cannot use any other theorems unless you prove them first. (Note that the due date shown above is for the programming part. The due date of the hand-written part is later, as shown in the following submission guidelines.)

Exercise

  1. (5%) (Exercise R-4.24 of the textbook) Show that if d(n) is O(f(n)) and e(n) is O(g(n)), then d(n)-e(n) is not necessarily O(f(n)-g(n)).
  2. (5%) (Exercise C-4.8 of the textbook. Note that you need to prove it!) Give an example of a positive function f(n) such that f(n) is neither O(n) nor W(n).
  3. (5%) Prove or disapprove the following statement. ¡§For non-negative functions f, g, h, if f(n) = O(g(n)), then f(n) + h(n) = O(g(n) + h(n)).¡¨
  4. (5%) (Exercise R-4.7 of the textbook) The number of operations executed by algorithms A and B is $8 n \log n$ and $2n^2$, respectively. Determine $n_0$ such that A is better than B for $n \geq n_0$.

Submission guidelines

  1. Format: A4 blank paper(s). Please add your class information (Mon/Tue).
  2. Deadline: 4/19 (Tue) 23:00
  3. Location: 409: There will have two boxes outside the room. Please put your HW in the right box as indicated. And we will place the boxes on 4/18.

Programming Part: Nonograms (Maze traversal, 80%)

Problem definition

In this homework, you need to write a program to solve the game of nonogram. More info about the game can be found at Wikipedia (English, Chinese), or º©½Í nonogram (in Chinese). You can also google "nonogram" or "picross" to find interactive pages to play the game, such as here and there.

Write a program to output the map based on the input criteria. The input has the following format:

m n ¡ö The numbers of rows and columns of the bit map (matrix) a11 a12 . . . . . . ¡ö lengths of unbroken lines in row 1 a21 a22 . . . . . . ¡ö lengths of unbroken lines in row 2 . . . am1 am2 . . . . . . ¡ö lengths of unbroken lines in row m b11 b12 . . . . . . ¡ö lengths of unbroken lines in column 1 b21 b22 . . . . . . ¡ö lengths of unbroken lines in column 2 . . . bn1 bn2 . . . . . . ¡ö lengths of unbroken lines in column m

The output format is as shown in the following test cases.

Here are some examples of nonograms:

One way to solve the problem is shown here. You can find many different methods, from simple to complex ones, to solve the problem.

Requirements & suggestions

Test cases

Note that the answer may not be unique for each problem.
  1. Basic test cases
    1. Simplest (3x2): input, output
    2. Checker board (4x4):input, output
    3. Tree (5x5): input, output
    4. Pig face (14x13): input, output
    5. Scorpion (20x20): input, output
    6. Beckham (20x20): input, output
    7. Smoke (20x20): input, output
    8. Cat (25x25): input, output
  2. Random test cases

Submission guidelines

Please submit your code with GitHub as directed in the GitHub submission guide. Your directory structure (under GitHub repository) should be:
  1. hw3/*, your source code.
  2. hw3/Makefile, where the TAs can use the command ¡¨make¡¨ on CSIE R217 linux machines to compile your code, and ¡¨make run¡¨ to run your program.
You have to make sure your code can be compiled on CSIE R217 linux machines with your Makefile and run normally since we will test your program on CSIE R217 linux machines.